package com.heima.service.impl;

import com.heima.entry.FindNotWorkByTime;
import com.heima.entry.NotWorkUser;
import com.heima.entry.SelectWork;
import com.heima.mapper.UserPracticeMapper;
import com.heima.entry.UserPractice;
import com.heima.pojo.utils.Result;
import com.heima.service.UserPracticeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.List;

/**
 * @ClassName UserPracticeServiceImpl
 * @Author Administrator
 * @create 2022/11/13 14:27
 */
@Controller
public class UserPracticeServiceImpl implements UserPracticeService {
    @Autowired
    UserPracticeMapper userPracticeMapper;


    @Override
    public Result findAll(SelectWork selectWork) throws ParseException {

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        String time = formatter.format(selectWork.getTime());

/*        String t = formatter.format(selectWork.getTime());
        Date parse = formatter.parse(t);
        selectWork.setTime(parse);*/

        List<UserPractice> list = userPracticeMapper.findAll(time,selectWork.getType());

        return new Result(0,"操作成功",list);
    }

    @Override
    public Result findNotWorkByTime(FindNotWorkByTime findNotWorkByTime) {
        //查询日期格式转换
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd");
        //开始
        String startTime = formatter.format(findNotWorkByTime.getStartTime());
        //结束
        String endTime = formatter.format(findNotWorkByTime.getEndTime());
        List<NotWorkUser> list = userPracticeMapper.findNotWorkByTime(startTime,endTime,findNotWorkByTime.getType());
        return new Result(0,"操作成功",list);
    }


}
